<?php
/**
 * Model Bill_product
 * @package Model
 * @author chinhpv.hp
 */

class Model_BillProduct extends Zend_Db_Table_Abstract{
	protected $_name = 'bill_product';
	
	protected $_referenceMap = array(
		"Bill"=>array(
			"columns"=>"bill_id",
			"refTableClass"=>"Model_Bill",
			"refColumns"=>"id"),
		"Product"=>array(
			"columns"=>"product_id",
			"refTableClass"=>"Model_Product",
			"refColumns"=>"id"));
	/**
	 * thêm bill product mới
	 * @param int $bill_id id bill
	 * @param int $product_id id product
	 * @param int $quantity số lượng sản phẩm
	 * 
 	 */
	function addBillProduct($bill_id, $product_id,$quantity){
		$bill_product = $this->createRow();
		$bill_product->bill_id = $bill_id;
		$bill_product->product_id = $product_id;
		$bill_product->quantity = $quantity;
		$bill_product->save();
	}
	/**
	 * get all bill_product
	 * @return Zend_Db_Table_Row
	 */
	public function getAllBill(){
		return $this->fetchAll();
		}
	
	/**
	 * get bill_product by id
	 */
	public function getBill_productByID($bill_id){
		return $this->find($bill_id)->current();
	}
	/**
	 * delete 
	 */
	public function deleteBillProduct($id){
	if(is_numeric($id)){
			return $this->delete('bill_id='.$id);
		}else{
			
			return $this->delete('bill_id in ('.$id.')');
		}
	}
	
}